package com.herench.bridge;

import org.apache.commons.lang.time.DateFormatUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by ThinkPad on 2017/6/4.
 */
public class MsgTemplate {

    public static Document getTotalOutMsgTpl(){
        try {
            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<BITCRoot>\n" +
                    "    <CommitData/>\n" +
                    "    <ReturnData>\n" +
                    "        <Data>\n" +
                    "            <DataRow AlipayTransactionCOUNT =\"\"  AlipayTransactionAMT=\"\" AppCCBTransactionCOUNT =\"\"  AppCCBTransactionAMT=\"\" CCBTransactionCOUNT =\"\"  CCBTransactionAMT=\"\" />\n" +
                    "        </Data>\n" +
                    "    </ReturnData>\n" +
                    "    <ClientInfo>\n" +
                    "        <Info METHOD=\"ValidateTotalAccount\" TOKEN=\"交易密钥\" OPT_ID=\"操作者ID\" OPT_NAME=\"操作者姓名\" OPT_IP=\"操作者IP\" OPT_DATE=\"操作时间\" OPT_GUID=\"客户端操作的唯一ID\" OPT_ACCT=\"客户端账期\"/>\n" +
                    "    </ClientInfo>\n" +
                    "    <ServerInfo>\n" +
                    "        <Info DEV_ID=\"设备ID\" DEV_IP=\"设备IP\" DEV_DATE=\"设备时间\" DEV_GUID=\"服务端操作的唯一ID\" DEV_ACCT=\"服务端账期\"/>\n" +
                    "    </ServerInfo>\n" +
                    "    <Result>\n" +
                    "        <Info EXECUTE_STATUS=\"执行结果\" EXECUTE_MESSAGE=\"执行信息\"/>\n" +
                    "    </Result>\n" +
                    "</BITCRoot>\n";
            Document document = DocumentHelper.parseText(xml);
            return document;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Document getTotalInMsgTpl(Date date){
        try {
            if (date==null){
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_YEAR,-1);
                date = calendar.getTime();
            }
            String dateStr = DateFormatUtils.format(date,"yyyy-MM-dd");
            String temeStr = DateFormatUtils.format(date,"HH:mm:ss");

            String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<BITCRoot>\n" +
                    "    <CommitData>\n" +
                    "        <Data>\n" +
                    "            <DataRow Reconciliation_Date=\""+dateStr+"\" />\n" +
                    "        </Data>\n" +
                    "    </CommitData>\n" +
                    "    <ReturnData/>\n" +
                    "    <ClientInfo>\n" +
                    "        <Info METHOD=\"ValidateTotalAccount\" TOKEN=\"交易密钥\" OPT_ID=\"操作者ID\" OPT_NAME=\"操作者姓名\" OPT_IP=\"操作者IP\" OPT_DATE=\"操作时间\" OPT_GUID=\"客户端操作的唯一ID\" OPT_ACCT=\"客户端账期\"/>\n" +
                    "    </ClientInfo>\n" +
                    "    <ServerInfo>\n" +
                    "        <Info DEV_ID=\"\" DEV_IP=\"\" DEV_DATE=\"\" DEV_GUID=\"\" DEV_ACCT=\"\"/>\n" +
                    "    </ServerInfo>\n" +
                    "    <Result>\n" +
                    "        <Info EXECUTE_STATUS=\"0\" EXECUTE_MESSAGE=\"\"/>\n" +
                    "    </Result>\n" +
                    "</BITCRoot>";
            Document document = DocumentHelper.parseText(xml);
            return document;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;

    }



    public static Document getDetailOutMsgTpl(){
        try {
            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<BITCRoot>\n" +
                    "    <CommitData/>\n" +
                    "    <ReturnData>\n" +
                    "        <Data>\n" +
                    "        </Data>\n" +
                    "    </ReturnData>\n" +
                    "    <ClientInfo>\n" +
                    "        <Info METHOD=\"ValidateAccountDetail\" TOKEN=\"交易密钥\" OPT_ID=\"操作者ID\" OPT_NAME=\"操作者姓名\" OPT_IP=\"操作者IP\" OPT_DATE=\"操作时间\" OPT_GUID=\"客户端操作的唯一ID\" OPT_ACCT=\"客户端账期\"/>\n" +
                    "    </ClientInfo>\n" +
                    "    <ServerInfo>\n" +
                    "        <Info DEV_ID=\"设备ID\" DEV_IP=\"设备IP\" DEV_DATE=\"设备时间\" DEV_GUID=\"服务端操作的唯一ID\" DEV_ACCT=\"服务端账期\"/>\n" +
                    "    </ServerInfo>\n" +
                    "    <Result>\n" +
                    "        <Info EXECUTE_STATUS=\"执行结果\" EXECUTE_MESSAGE=\"执行信息\"/>\n" +
                    "    </Result>\n" +
                    "</BITCRoot>\n";
            Document document = DocumentHelper.parseText(xml);
            return document;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Document getDetailInMsgTpl(Date date){
        try {
            if (date==null){
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_YEAR,-1);
                date = calendar.getTime();
            }
            String dateStr = DateFormatUtils.format(date,"yyyy-MM-dd");
            String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<BITCRoot>\n" +
                    "    <CommitData>\n" +
                    "        <Data>\n" +
                    "            <DataRow Reconciliation_Date=\""+dateStr+"\" />\n" +
                    "        </Data>\n" +
                    "    </CommitData>\n" +
                    "    <ReturnData/>\n" +
                    "    <ClientInfo>\n" +
                    "        <Info METHOD=\"ValidateAccountDetail\" TOKEN=\"交易密钥\" OPT_ID=\"操作者ID\" OPT_NAME=\"操作者姓名\" OPT_IP=\"操作者IP\" OPT_DATE=\"操作时间\" OPT_GUID=\"客户端操作的唯一ID\" OPT_ACCT=\"客户端账期\"/>\n" +
                    "    </ClientInfo>\n" +
                    "    <ServerInfo>\n" +
                    "        <Info DEV_ID=\"\" DEV_IP=\"\" DEV_DATE=\"\" DEV_GUID=\"\" DEV_ACCT=\"\"/>\n" +
                    "    </ServerInfo>\n" +
                    "    <Result>\n" +
                    "        <Info EXECUTE_STATUS=\"0\" EXECUTE_MESSAGE=\"\"/>\n" +
                    "    </Result>\n" +
                    "</BITCRoot>";
            Document document = DocumentHelper.parseText(xml);
            return document;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;

    }

    public static Document getCommonOutMsgTpl(){
        try {
            String xml =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                    "<BITCRoot>\n" +
                    "    <CommitData/>\n" +
                    "    <ReturnData>\n" +
                    "        <Data>\n" +
                    "        </Data>\n" +
                    "    </ReturnData>\n" +
                    "    <ClientInfo>\n" +
                    "        <Info METHOD=\"\" TOKEN=\"交易密钥\" OPT_ID=\"操作者ID\" OPT_NAME=\"操作者姓名\" OPT_IP=\"操作者IP\" OPT_DATE=\"\" OPT_GUID=\"客户端操作的唯一ID\" OPT_ACCT=\"客户端账期\"/>\n" +
                    "    </ClientInfo>\n" +
                    "    <ServerInfo>\n" +
                    "        <Info DEV_ID=\"设备ID\" DEV_IP=\"设备IP\" DEV_DATE=\"设备时间\" DEV_GUID=\"服务端操作的唯一ID\" DEV_ACCT=\"服务端账期\"/>\n" +
                    "    </ServerInfo>\n" +
                    "    <Result>\n" +
                    "        <Info EXECUTE_STATUS=\"执行结果\" EXECUTE_MESSAGE=\"执行信息\"/>\n" +
                    "    </Result>\n" +
                    "</BITCRoot>";
            Document document = DocumentHelper.parseText(xml);
            return document;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }

}
